// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import GameDataController from "../../Controller/GameDataController";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Label)
    nowLifes: cc.Label = null;

    @property(cc.Label)
    currLevel: cc.Label = null;

    @property(cc.Label)
    HighScore: cc.Label = null;

    @property(cc.Label)
    CurrScore: cc.Label = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.nowLifes.string = GameDataController.getInstance().CurrLeftLifes.toString();
        this.currLevel.string = GameDataController.getInstance().CurrLevel.toString();
        this.HighScore.string = GameDataController.getInstance().HighScore.toString();
        this.CurrScore.string = GameDataController.getInstance().CurrScore.toString();

        let enterCallBack = cc.callFunc(this.enterLevelMainGame, this);
        this.node.runAction(cc.sequence(cc.delayTime(3), enterCallBack));
    }

    start () {
    }

    //进入相应的关卡界面
    enterLevelMainGame(){
        //TODO
        cc.loader.loadRes("prefabs/LevelMap/LevelMap_1", cc.Prefab, null, (error: Error, resource: cc.Prefab) =>{
            if(error){

            }else{
                if(resource){
                    let newMap = cc.instantiate(resource);
                    cc.director.loadScene("scene/MainGameScene", ()=>{
                        let currScene = cc.director.getScene();
                    });
                }
            }
        })
    }
    // update (dt) {}
}
